using Digitalmes.Application.Mes.Traceability.Products.Queries;

namespace Digitalmes.WebApi.Endpoints.Mes.Traceability;

/// <summary>
/// 产品数据追溯查询终结点。
/// </summary>
public sealed class ProductTraceabilityEndpoint : EndpointGroupBase
{
    public override void Map(WebApplication app)
    {
        app.MapGroup(this, "mes/traceability", "product")
            .RequireAuthorization()
            .MapGet(GetProductLimitListAsync, "limit")
            .MapGet(GetProductProcessStepListAsync, "step")
            .MapGet(GetProductProcessTimelineAsync, "timeline")
            .MapGet(GetProductStepProcessDataAsync, "stepData");
    }

    [EndpointDescription("产品过程追溯根据零件码模糊查询")]
    public async Task<IApiResult> GetProductLimitListAsync(ISender sender, [AsParameters] GetProductLimitQuery query)
    {
        var result = await sender.Send(query);
        return result.ToApiResult();
    }

    [EndpointDescription("产品生产工艺步骤查询")]
    public async Task<IApiResult> GetProductProcessStepListAsync(ISender sender, [AsParameters] GetProcessStepQuery query)
    {
        var result = await sender.Send(query);
        return result.ToApiResult();
    }

    [EndpointDescription("产品工艺步骤时间线查询")]
    public async Task<IApiResult> GetProductProcessTimelineAsync(ISender sender, [AsParameters] GetProcessTimelineQuery query)
    {
        var result = await sender.Send(query);
        return result.ToApiResult();
    }

    [EndpointDescription("工艺步骤以及其所有的工步的过程数据查询")]
    public async Task<IApiResult> GetProductStepProcessDataAsync(ISender sender, [AsParameters] GetStepProcessDataQuery query)
    {
        var result = await sender.Send(query);
        return result.ToApiResult();
    }
}
